package com.huajin100.redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisShardInfo;
import redis.clients.jedis.ShardedJedisPool;

import java.util.LinkedList;
import java.util.List;
import java.util.ResourceBundle;

/**
 * Author:     cc
 * Revision:   #
 * Date:       2014/11/18 11:44
 */
public class xxx {
    private static JedisPool pool;
    static {
        ResourceBundle bundle = ResourceBundle.getBundle("redis");
        if (bundle == null) {
            throw new IllegalArgumentException(
                    "[redis.properties] is not found!");
        }
        JedisPoolConfig config = new JedisPoolConfig();
//        config.setMaxActive(Integer.valueOf(bundle.getString("redis.pool.maxActive")));
        /*config.setMaxIdle(Integer.valueOf(bundle.getString("redis.pool.maxIdle")));
//        config.setMaxWait(Long.valueOf(bundle.getString("redis.pool.maxWait")));
        config.setTestOnBorrow(Boolean.valueOf(bundle.getString("redis.pool.testOnBorrow")));
        config.setTestOnReturn(Boolean.valueOf(bundle.getString("redis.pool.testOnReturn")));
        pool = new JedisPool(config, bundle.getString("redis.ip"),Integer.valueOf(bundle.getString("redis.port")));*/
        JedisShardInfo jedisShardInfo = new JedisShardInfo(
                bundle.getString("redis.ip"), Integer.valueOf(bundle.getString("redis.port")));
        List<JedisShardInfo> list = new LinkedList<JedisShardInfo>();
        list.add(jedisShardInfo);

        ShardedJedisPool pool = new ShardedJedisPool(config, list);
    }

    public static void main(String [] args) {
        Jedis jedis = pool.getResource();
        String keys = "name";
        jedis.del(keys);

        jedis.set(keys, "lwc");
        String value = jedis.get(keys);
        System.out.println(value);

        pool.returnResource(jedis);
    }
}
